package com.eightgroups.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Author: zzc
 * Email: 805046440@qq.com
 * Date: 2017/9/27
 * Time: 10:45
 * Describe: JSON工具类
 */
public class JsonMapUtil {

    /**
     * 将json格式的字符串 放到map中
     * @param jsonStr
     * @return
     */
    public static Map<String, String> parseToMap(String jsonStr){
        JSONObject jsonObj = JSON.parseObject(jsonStr);
        Set<String> jsonKeySet = jsonObj.keySet();
        Map<String, String> resultMap = new HashMap<>();
        Iterator<String> it = jsonKeySet.iterator();
        while (it.hasNext()) {
            String key = it.next();
            resultMap.put(key, jsonObj.getString(key));
        }
        return resultMap;
    }

}
